package com.kayak.tg.client.config;

import com.baidu.unbiz.fluentvalidator.interceptor.FluentValidateInterceptor;
import com.kayak.tg.client.component.ParamsValidateCallback;
import org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 参数校验拦截器配置
 * @author xiamh
 * @date 19/1/3
 */
@Configuration
public class FluentValidatorConfiguration {

    @Autowired
    private ParamsValidateCallback validateCallback;    //校验回调对象

    /**
     * 设置参数校验拦截器对象
     * @return
     */
    @Bean("fluentValidateInterceptor")
    public FluentValidateInterceptor fluentValidateInterceptor(){
        FluentValidateInterceptor validateInterceptor = new FluentValidateInterceptor();
        validateInterceptor.setCallback(validateCallback);
        validateInterceptor.setLocale("zh_CN");
//        validateInterceptor.setHibernateDefaultErrorCode(10000);
        return validateInterceptor;
    }

    /**
     * 配置参数校验拦截器
     * @return
     */
    @Bean
    public BeanNameAutoProxyCreator beanNameAutoProxyCreator(){
        BeanNameAutoProxyCreator proxyCreator = new BeanNameAutoProxyCreator();
        proxyCreator.setBeanNames("*Controller","*ServiceImpl");              //配置拦截对象 如拦截service(*ServiceImpl)
        proxyCreator.setInterceptorNames("fluentValidateInterceptor");        //配置拦截器
        return proxyCreator;
    }

}
